﻿
@{
    ViewBag.Title = "OutpatientReprintOrSupplementPrint";
    Layout = "~/Views/Shared/_Index.cshtml";
}

<style type="text/css">
    .toolbarmargin {
        margin-top:10px;
        float: right;
    }
</style>

<form id="form1">
    <div class="panel panel-default" style="margin-top:10px;">
        <div class="panel-heading navb-bg">
            筛选条件
        </div>
        <div style="padding: 2px;padding-right:20px;">
            <table class="form">
                <tr>
                    <th class="formTitle">开始日期：</th>
                    <td class="formValue">
                        <input id="txtstartDate" type="text" class="form-control input-wdatepicker " value="@DateTime.Now.ToString("yyyy-MM-01 00:00:00")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss' })" />
                    </td>
                    <th class="formTitle">结束日期：</th>
                    <td class="formValue">
                        <input id="txtendDate" type="text" class="form-control input-wdatepicker " value="@DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd HH:mm:ss' })" />
                    </td>
                    <th class="formTitle">结算内码：</th>
                    <td class="formValue">
                        <input type="text" class="form-control" id="txtjsnm" name="txtjsnm" />
                    </td>
                    <td class="formValue" rowspan="2">
                        <input type="button" id="btn_search" class="btn btn-default btn-md" style="width:50px; height:45px; margin-left: 40px" value="查询" />
                    </td>
                </tr>
                <tr>
                    <th class="formTitle">卡号：</th>
                    <td class="formValue">
                        <div class="row">
                            <div class="col-md-9">
                                <input type="text" class="form-control" id="txtkh" name="txtkh" />
                            </div>
                            <div class="col-md-3" style="text-align:right;">
                                <input type="button" class="btn btn-default btn-md" style="width:100%" value="刷卡" onclick="SK()" />
                            </div>
                        </div>
                    </td>
                    <th class="formTitle">原发票号：</th>
                    <td class="formValue">
                        <input type="text" class="form-control" id="txtyfph" name="txtyfph" />
                    </td>
                    <th class="formTitle"></th>
                    <td class="formValue"></td>
                </tr>
            </table>
        </div>
    </div>
    <div style="background-color: #fff;width:99%;">
        <table id="gridMzjsRecords"></table>
    </div>
    <div style="background-color: #fff;width:99%;"> 
        <table id="gridMzjsMXInfo"></table>
    </div>
  <div class="gridPanel">
        <table id="gridMzjsRecords"></table>
        <div id="gridPager" rel="form1"></div>
    </div>
    <input type="text" id="txtfph" name="txtfph" hidden="hidden">
</form>

@Html.Partial("_BottomButtonsView", new Newtouch.HIS.Web.Core.Models.BottomButtonViewModel()
{
    ShowKeyList = new int[] { 4, 6, 7, 8, 9, 10 },
    F6Text= "打印明细",
    F7Text= "打印发票",
    F8Text= "补打",
    F9Text= "重打"
})

<script>
    $(function () {
        //浏览器窗口调整大小时重新加载jqGrid的宽
        $(window).resize(function () {
            initLayout("MyTabGrid");
        });
        //结算主记录
        gridMzjsRecordsData();
        //全选/全不选：找到Grid中 title的checkbox，注册一个onclick事件，当click时，加载明细
        $("table input[type=checkbox]:eq(0)").bind("click", function () {
           
            btn_selectrow();
        });

    })

    //刷卡
    function SK() {
        $.modalAlert("功能正在开发中", 'warning');
        return false;
    }

    //门诊发票信息List
    function gridMzjsRecordsData() {
        var $gridMzjsRecords = $("#gridMzjsRecords");
        $gridMzjsRecords.dataGrid({
            postData: getSearchPostData(),
            height: 150,
            url: "",
            colModel: [
                { label: '全选', name: '', width: 80, align: 'left' },
                { label: '结算内码', name: 'jsnm', width: 120, align: 'left' },
                { label: '姓名', name: 'xm', width: 120, align: 'left' },
                { label: '卡号', name: 'kh', width: 120, align: 'left' },
                { label: '发票号', name: 'xfph', width: 120, align: 'left' },
                { label: '收费员', name: 'rymc', width: 120, align: 'left' },
                { label: '结算日期', name: 'CreateTime', width: 130, align: 'left' },
                {
                    label: '总金额', name: 'zje', width: 120, align: 'left', formatter: function (cellvalue) {
                        return cellvalue ? cellvalue.toFixed(2) : "0.00";
                    }
                }

            ],
            multiselect: true,
            pager: "#gridPager",
            sortname: 'CreateTime desc',
            viewrecords: true,
            onSelectRow_page: function (rowid) {
                btn_selectrow();
            }

        });

        $("#btn_search").click(function () {
            $gridMzjsRecords.jqGrid('setGridParam', {
                postData: getSearchPostData(), url: '/OutpatientManage/OutpatientChargeQuery/LoadMzjsRecords'
            }).trigger('reloadGrid');
        });
        //$("#btn_search").trigger('click');
    }
    function getSearchPostData() {
        var startDate = $("#txtstartDate").val();
        var endDate = $("#txtendDate").val();
        var jsnm = $("#txtjsnm").val();
        var kh = $("#txtkh").val();
        var yfph = $("#txtyfph").val();
        return { startDate: startDate, endDate: endDate, jsnm: jsnm, kh: kh, yfph: yfph };
    };

    //单击事件
    function btn_selectrow()
    {
        //每次单击，先清空明细 再重新加载所有选中行明细
        $('#gridMzjsMXInfo').jqGrid("clearGridData");
        var rowsData = $("#gridMzjsRecords").jqGrid("getRowData_AllLine", true);
        var rowsDataArray = JSON.parse(rowsData)
        var jsnmStr = "";
        for (var i = 0; i < rowsDataArray.length; i++) {
            jsnmStr += rowsDataArray[i].jsnm+",";
        }
        $.najax({
            type: "POST",
            url: "/OutpatientManage/OutpatientChargeQuery/LoadMzjsMXRecords",
            data: { jsnmStr: jsnmStr },
            dataType: "json",
            success: function (ajaxresp) {
                ConvertObjectMethod(ajaxresp.data);
            }
        });
    }
    function ConvertObjectMethod(settleDetailDto)
    {
        var MXInfoList = [];
        //mz_ghxm
        for (var i = 0; i < settleDetailDto.mz_ghxmList.length; i++) {
            var obj = new Object();
            obj.cfh = "";
            obj.lx = settleDetailDto.mz_ghxmList[i].dlmc;
            obj.xmmc = settleDetailDto.mz_ghxmList[i].sfxmmc;
            obj.dw = settleDetailDto.mz_ghxmList[i].djdw;
            
            if (settleDetailDto.pzmzEntity.pz == settleDetailDto.mz_ghxmList[i].sfxm) {
                obj.dj = settleDetailDto.mz_ghxmList[i].dj;
                obj.zfbl = settleDetailDto.mz_ghxmList[i].zfbl;
                obj.sl = "1.00";
                obj.je = settleDetailDto.mz_ghxmList[i].je;
            }
            else
            {
                obj.dj = parseFloat(settleDetailDto.mz_ghxmList[i].dj) + parseFloat(settleDetailDto.mz_ghxmList[i].fwfdj);
                obj.zfbl = settleDetailDto.mz_ghxmList[i].zfbl;
                obj.sl = settleDetailDto.mz_ghxmList[i].sl;
                obj.je = settleDetailDto.mz_ghxmList[i].je;
            }
            obj.isGh = settleDetailDto.IsGh;
            MXInfoList.push(obj);
        }
        //mz_xm
        for (var i = 0; i < settleDetailDto.mz_xmList.length; i++) {
            var obj = new Object();
            obj.cfh = "";
            obj.lx = settleDetailDto.mz_xmList[i].dlmc;
            obj.xmmc = settleDetailDto.mz_xmList[i].sfxmmc;
            obj.dw = settleDetailDto.mz_xmList[i].djdw;

            if (settleDetailDto.pzmzEntity.pz == settleDetailDto.mz_xmList[i].sfxm) {
                obj.dj = settleDetailDto.mz_xmList[i].dj;
                obj.zfbl = settleDetailDto.mz_xmList[i].zfbl;
                obj.sl = "1.00";
                obj.je = settleDetailDto.mz_xmList[i].je;
            }
            else {
                obj.dj = parseFloat(settleDetailDto.mz_xmList[i].dj) + parseFloat(settleDetailDto.mz_xmList[i].fwfdj);
                obj.zfbl = settleDetailDto.mz_xmList[i].zfbl;
                obj.sl = settleDetailDto.mz_xmList[i].sl;
                obj.je = settleDetailDto.mz_xmList[i].je;
            }
            obj.isGh = settleDetailDto.IsGh;
            MXInfoList.push(obj);
        }
        //mz_cfmx
        for (var i = 0; i < settleDetailDto.mz_cfmxList.length; i++) {
            var obj = new Object();
            obj.cfh = settleDetailDto.mz_cfmxList[i].cfh;
            obj.lx = settleDetailDto.mz_cfmxList[i].dlmc;
            obj.xmmc = settleDetailDto.mz_cfmxList[i].ypmc;
            obj.dw = settleDetailDto.mz_cfmxList[i].djdw;

            if (settleDetailDto.pzmzEntity.pz == settleDetailDto.mz_cfmxList[i].sfxm) {
                obj.dj = settleDetailDto.mz_cfmxList[i].dj;
                obj.zfbl = settleDetailDto.mz_cfmxList[i].zfbl;
                obj.sl = "1.00";
                obj.je = settleDetailDto.mz_cfmxList[i].je;
            }
            else {
                obj.dj = parseFloat(settleDetailDto.mz_cfmxList[i].dj) + parseFloat(settleDetailDto.mz_cfmxList[i].fwfdj);
                obj.zfbl = settleDetailDto.mz_cfmxList[i].zfbl;
                obj.sl = settleDetailDto.mz_cfmxList[i].sl;
                obj.je = settleDetailDto.mz_cfmxList[i].je;
            }
            obj.isGh = settleDetailDto.IsGh;
            MXInfoList.push(obj);
        }
        $('#gridMzjsMXInfo').newtouchLocalDataGrid(null, MXInfoList);
    }

    //门诊发票明细 jGrid声明
    $('#gridMzjsMXInfo').newtouchLocalDataGrid({
        height: 110,
        caption: "结算明细",
        unwritten: false,
        sortable: false,
        colModel: [
            { label: '处方号', name: 'cfh', width: 140, key: true },
            { label: '类型', name: 'lx', width: 140, align: 'left' },
            { label: '项目名称', name: 'xmmc', width: 160, align: 'left' },
            { label: '单位', name: 'dw', width: 120, align: 'left' },
            { label: '单价', name: 'dj', width: 110, align: 'left' },
            { label: '自负比例', name: 'zfbl', width: 110, align: 'left' },
            { label: '数量', name: 'sl', width: 100, align: 'left' },
            {
                label: '金额', name: 'je', width: 100, align: 'left', formatter: function (cellvalue) {
                    return cellvalue ? cellvalue.toFixed(2) : "0.00";
                }
            },
            { label: 'isGh', name: 'isGh', hidden: true, align: 'left' }

        ]
    });

    //打印明细
    function PrintMxData()
    {
        $.modalAlert("功能正在开发中", 'warning');
        return false;

        var reccount = $("#gridMzjsRecords").getGridParam("selarrrow").length;
        if (reccount > 0) {
            var rowsData = $("#gridMzjsRecords").jqGrid("getRowData_AllLine", true);
            var rowsDataArray = JSON.parse(rowsData)
            var jsnmStr = "";
            for (var i = 0; i < rowsDataArray.length; i++) {
                jsnmStr += rowsDataArray[i].jsnm + ",";
            }
            $.najax({
                type: "POST",
                url: "/OutpatientManage/OutpatientChargeQuery/PrintMxData",
                data: { jsnmStr: jsnmStr },
                dataType: "json",
                success: function (ajaxresp) {

                }
            });


        } else {
            $.modalAlert("请选择要打印明细的结算记录", 'warning');
            return;
        }
        
    }

    //打印发票
    function InvoicePrint()
    {
        $.modalAlert("功能正在开发中", 'warning');
        return false;

        var reccount = $("#gridMzjsRecords").getGridParam("selarrrow").length;
        if (reccount == 0)
        {
            $.modalAlert("请选择结算信息", 'warning');
            return;
        } else if (reccount > 1) {
            $.modalAlert("只能打印一条结算信息的发票", 'warning');
            return;

        } else
        {
            //勾选的行
            var rowsData = $("#gridMzjsRecords").jqGrid("getRowData_AllLine", true);
            var rowsDataArray = JSON.parse(rowsData);
            var jsnm = rowsDataArray[0].jsnm;
            var isGh = $("#gridMzjsMXInfo").jqGrid('getGridParam', 'data')[0].isGh;
        }
        $.najax({
            type: "POST",
            url: "/OutpatientManage/OutpatientChargeQuery/CheckPintInfo",
            data: { jsnm: jsnm },
            dataType: "json",
            success: function (ajaxresp) {
                //打印发票
                PrintInvoice(jsnm, isGh);
            }
        });
    }

    //弹出发票号的窗口
    function ShowInvoicePanel() {
        $.modalOpen({
            id: "InvoiceNoChoosePanel",
            title: "选发票号",
            url: "/OutpatientManage/OutpatientReg/ChooseInvoice",
            width: "300px",
            height: "200px",
            callBack: function (iframeId) {
                top.InvoiceNoChoosePanel.checkFPH();    //窗口点确定的回调函数
            }
        });
    }

    //打印发票
    function PrintInvoice(jsnm, isGh)
    {
        $.najax({
            type: "POST",
            url: "/OutpatientManage/OutpatientChargeQuery/PrintInvoice",
            data: { jsnm: jsnm, isGh: isGh },
            dataType: "json",
            success: function (ajaxresp) {

            }
        });
    }

    //补打
    function SupplementPrint() {

        $.modalAlert("功能正在开发中", 'warning');
        return false;

        var reccount = $("#gridMzjsRecords").getGridParam("selarrrow").length;
        if (reccount == 0) {
            $.modalAlert("请选择结算信息", 'warning');
            return;
        } else if (reccount > 1) {
            $.modalAlert("只能重打一条结算信息", 'warning');
            return;
        } else {
            //勾选的行
            var rowsData = $("#gridMzjsRecords").jqGrid("getRowData_AllLine", true);
            var rowsDataArray = JSON.parse(rowsData);
            var jsnm = rowsDataArray[0].jsnm;
            var isGh = $("#gridMzjsMXInfo").jqGrid('getGridParam', 'data')[0].isGh;
        }
        $.najax({
            type: "POST",
            url: "/OutpatientManage/OutpatientChargeQuery/CheckPintInfo",
            data: { jsnm: jsnm },
            dataType: "json",
            success: function (ajaxresp) {
                //补打
                ExecSupplementPrint(jsnm, isGh);
            }
        });
    }
    //补打
    function ExecSupplementPrint(jsnm,isGh)
    {
        $.najax({
            type: "POST",
            url: "/OutpatientManage/OutpatientChargeQuery/SupplementPrint",
            data: { jsnm: jsnm, isGh: isGh },
            dataType: "json",
            success: function (ajaxresp) {

            }
        });

    }

    //重打
    function RePrint() {

        $.modalAlert("功能正在开发中", 'warning');
        return false;

        var reccount = $("#gridMzjsRecords").getGridParam("selarrrow").length;
        if (reccount == 0) {
            $.modalAlert("请选择结算信息", 'warning');
            return;
        }
        if (reccount > 1) {
            $.modalAlert("只能重打一条结算信息", 'warning');
            return;
        } else
        {
            //勾选的行
            var rowsData = $("#gridMzjsRecords").jqGrid("getRowData_AllLine", true);
            var rowsDataArray = JSON.parse(rowsData);
            var jsnm = rowsDataArray[0].jsnm;
        }
        $.najax({
            type: "POST",
            url: "/OutpatientManage/OutpatientChargeQuery/CheckPintInfo",
            data: { jsnm: jsnm },
            dataType: "json",
            success: function (ajaxresp) {
                //弹出发票号窗口
                ShowInvoicePanel();
            }
        });
    }

    //发票号窗口点击确定
    function chooseFPHSuccessCallback() {
        //勾选的行
        var rowsData = $("#gridMzjsRecords").jqGrid("getRowData_AllLine", true);
        var rowsDataArray = JSON.parse(rowsData);
        var jsnm = rowsDataArray[0].jsnm;
        var isGh = $("#gridMzjsMXInfo").jqGrid('getGridParam', 'data')[0].isGh;
        //重打
        ExecRePrint(jsnm, isGh);
    }

    //重打
    function ExecRePrint(jsnm,isGh)
    {
        $.najax({
            type: "POST",
            url: "/OutpatientManage/OutpatientChargeQuery/RePrint",
            data: { jsnm: jsnm, pageFph: $("#txtfph").val(), isGh: isGh },
            dataType: "json",
            success: function (ajaxresp) {
                $("#btn_search").trigger('click');
            }
        });

    }
    //快捷键：清除
    function newtouch_event_f4() {
        //清空Grid 
        $('#gridMzjsRecords').jqGrid("clearGridData");
        $('#gridMzjsMXInfo').jqGrid("clearGridData");
    }
    //快捷键：打印明细
    function newtouch_event_f6() {
        PrintMxData();
    }
    //快捷键：打印发票
    function newtouch_event_f7() {
        InvoicePrint();
    }
    //快捷键：补打
    function newtouch_event_f8() {
        SupplementPrint();
    }
    //快捷键：重打
    function newtouch_event_f9() {
        RePrint();
    }
</script>

